package com.bases {
	import com.Interface.IBase;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flashx.textLayout.formats.TextAlign;

	public class TLable extends TUIComponent implements IBase {
		protected var lbl:TextField;
		protected var format:TextFormat;

		public function TLable(){
			this.lbl = new TextField();
			this.addChild(lbl);
			this.lbl.type     = "dynamic";
			//this.lbl.autoSize = "left";
			
			this.mouseEnabled = false;
			this.mouseChildren = false;
			this.tabEnabled = false;
		}
		
		public function set text(value:String):void {
			if (value == null){
				this.lbl.text = '';
			} else {
				this.lbl.text = value;
			}
		}

		public function get text():String {
			return this.lbl.text;
		}

		override public function setSize(w:Number, h:Number):void {
//			super.setSize(w,h);
			this.lbl.width = w;
			this.lbl.height = h;
		}

		/**
		 * 设置Label的边框的颜色
		 * @param value uint
		 *
		 */
		public function set borderColor(value:uint):void {
			this.lbl.borderColor = value;
		}

		/**
		 * 设置字体大小和颜色
		 * @param size 字体
		 * @param color 颜色
		 *
		 */
		public function setFontSize(size:uint, color:uint = 0x000000):void {
			if (format == null){
				format = new TextFormat(null, size, color);
			} else {
				format.size = size;
				format.color = color;
			}
			setTextFormat(format);
		}

		/**
		 * 设置Label的原始字体样式
		 * @param value TextFormat
		 *
		 */
		public function set defaultTextFormat(value:TextFormat):void {
			this.lbl.defaultTextFormat = value;
		}

		/**
		 * 设置是否开启多行:true为开启,false为关闭
		 * @param value bool
		 *
		 */
		public function set multiline(value:Boolean):void {
			this.lbl.multiline = value;
		}

		/**
		 * 设置分行
		 * @param value true为支持自动分行,自动换行,false为取消分行
		 *
		 */
		public function set wordWrap(value:Boolean):void {
			this.lbl.multiline = value;
			this.lbl.wordWrap = value;
		}

		public function setTextFormat(format:TextFormat):void {
			this.lbl.setTextFormat(format);      //格式当前文本,appendText追加不影响,+=格式化被消取
			this.lbl.defaultTextFormat = format; //
		}

		/**返回文本宽度*/		
		public function get textWidth():Number {
			return this.lbl.textWidth;
		}

		/**
		 * 设置文本边框
		 * @param value true:有边框,false无边框
		 */
		public function set border(value:Boolean):void {
			this.lbl.border = value;
		}

		/**行与行之间的垂直间距*/
		public function set leading(value:int):void {
			format.leading = value;
			this.lbl.setTextFormat(format);
		}

		/**把label自适应大小*/
		public function adateLabel():void {
			this.setSize(this.lbl.textWidth + 5, this.lbl.textHeight + 3);
		}
	}
}